package com.luoxue.config;

import com.luoxue.datasource.DynamicDataSource;
import com.luoxue.entity.SysDataSource;
import com.luoxue.service.SysDataSourceService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;
import java.util.List;

@Configuration
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Resource
    SysDataSourceService sysDataSourceService;

    @Resource
    DynamicDataSource dynamicDataSource;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<SysDataSource> sysDataSourceList = sysDataSourceService.selectByCondition(null);
        dynamicDataSource.updateTargetDataSources(sysDataSourceList);
    }
}
